<?php
$sanitize_all_escapes = true;
$fake_register_globals = false;
if (!isset($_REQUEST['medico'])) 
    session_start();

$landingpage = "index.php?site=" . $_SESSION['site_id'];
if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite'])) {
    $pid = $_SESSION['pid'];
} else {
    session_destroy();
    header('Location: ' . $landingpage . '&w');
    exit;
}
$ignoreAuth = true;
require_once('../interface/globals.php');
require_once("$srcdir/patient.inc");

$result = getPatientData($pid);

function pic_array() {
    $picture_directory = "Patient Photograph"; //change this if you want
    $pics = array();
    $sql_query = "select documents.id from documents join categories_to_documents on documents.id = categories_to_documents.document_id join categories on categories.id = categories_to_documents.category_id where categories.name like ? and documents.foreign_id = ?";
    if ($query = sqlStatement($sql_query, array($picture_directory, $_SESSION['pid']))) {
        $results = sqlFetchArray($query);

        if (count($results) > 0) {
            /* echo "<pre>";
              print_r($results);
              echo "</pre>";die; */
            $tmp = $results['id'];
            if (isset($tmp)) {
                array_push($pics, "<div id='photograph' class='patient_pic'><img width='100px' height='100px' src='" . $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id=" . htmlspecialchars($_SESSION['pid'], ENT_QUOTES) . "&document_id=" . htmlspecialchars($tmp, ENT_QUOTES) . "&as_file=false' alt='Foto'></div>\n");
            } else {
                array_push($pics, "<div id='photograph' class='patient_pic'><img width='100px' src='images/patient.png' alt='Foto'></div>\n");
            }
        } else {
            array_push($pics, "<div id='photograph' class='patient_pic'><img height='88px' src='images/patient.png' alt='Foto'></div>\n");
        }
    }
    return $pics;
}
?>

<script type="text/javascript" language="JavaScript">
    $(document).ready(function() {
        // load views
        parent.$("#nombre_paciente").html('<a href="#" id="homepage" style="text-decoration: none; color: rgb(147, 142, 142);"><span id="welcome"><?php echo htmlspecialchars(xl('Welcome'), ENT_NOQUOTES); ?>&nbsp;<b><?php
$result = getPatientData($pid);
echo htmlspecialchars($result['fname'] . ' ' . $result['lname'], ENT_NOQUOTES);
?></b>: Expediente M&eacute;dico Personal</span></a>');
        $('#editar_paciente').click(function(e) {
            e.preventDefault();
            parent.$.fancybox({
                href: this.href,
                maxWidth: 850,
                minHeight: 380,
                fitToView: false,
                type: 'iframe',
                helpers: {
                    overlay: {
                        opacity: 0.3,
                        css: {
                            'background': 'rgba(255, 254, 254,0.85)'
                        }
                    } // overlay
                }, // helpers
                beforeShow: function() {
                    this.width = $('.fancybox-iframe').contents().find('html').width();
                    this.height = $('.fancybox-iframe').contents().find('html').height();
                },
                afterClose: function() {
                    parent.$("#get_patient_data").load("get_patient_data.php");
                }//afterClose
            }); // fancybox
        }); // click
    });
    /********************************************************/
</script>
<!--[if lt IE 7]>
<style type='text/css'>
        #simplemodal-container a.modalCloseImg {
                background:none;
                right:-14px;
                width:22px;
                height:26px;
                filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
                        src='img/x.png', sizingMethod='scale'
                );
        }
</style>
<![endif]-->
<div id="patient" class="border">
    <div id="patient_gnl">
        <div style="float: left; margin-left: 4px; border: 1px solid rgb(228, 227, 227);">
            <?php
            $tmp = pic_array();
            echo $tmp[0];
            ?>
        </div>
        <div style="float: right;width: 164px;">
            <p style="padding: 0px; font-size: 15px; margin-top: 0px; color: rgb(162, 162, 162);">
                <span style="color: rgb(67, 172, 164); font-weight: 500; font-size: 24px;"><?php echo htmlspecialchars($result['fname'] . " " . $result['lname'], ENT_NOQUOTES); ?></span><br/>
                <?php echo "<b>" . toDateView($result['DOB']) . "</b> <span style='font-size: 12px;'>(F. Nacimiento)</span>"; ?><br/>
                <?php echo "<b>" . $result['country_code'] . "</b> <span style='font-size: 12px;'>(Pa&iacute;s)</span>"; ?><br/>
            </p>
        </div>
    </div>
    <div class="patient_info_left">
        <a class="css_button_small iframe btnNav fancybox.iframe" href="demographics_full.php" title="Editar" id='editar_paciente'>
            <i class="icon-edit"></i>
        </a>
        <h2>GENERAL</h2>
        <p>
            Sexo: <span><?php
                if ($result['sex'] == "Female") {
                    echo "Femenino";
                } else {
                    echo "Masculino";
                }
                ?></span><br/>
            Email: <span><?php echo $result['email']; ?></span>
        </p>
    </div>
    <?php if ($result['city'] != '') { ?>
        <div class="patient_info_left">
            <h2>Direcci&oacute;n</h2>
            <p>
                <?php echo $result['city'] . " , " . $result['street']; ?>
            </p>
        </div>
    <?php } ?>
    <div class="patient_info_left">
        <h2>TELEFONO</h2>
        <p>
            <?php if ($result['phone_home'] != '') echo $result['phone_home'] . " (# Casa)<br/>"; ?>
            <?php echo $result['phone_cell'] . " (# Cel)"; ?>
        </p>
    </div>
</div>	